using Headsight.BPMN2WF.BPMN.Schemas;
using Headsight.BPMN2WF.Testing.TestObjCtors;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Headsight.BPMN2WF.Testing.TestObjCtorsTest
{
    [TestClass]
    public class tGatewayExclusiveCtorTest
    {
        private tGatewayExclusiveCtor _sut;

        [TestInitialize]
        public void SetUp()
        {
            _sut = new tGatewayExclusiveCtor(new tProcessCtor(), "**id**");
        }

        [TestMethod]
        public void Create()
        {
            var actual = _sut.Create();

            Assert.AreEqual("**id**", actual.id);
        }

        [TestMethod]
        public void WithName_is_chaining()
        {
            Assert.AreSame(_sut, _sut.WithName("**name**"));
        }

        [TestMethod]
        public void WithName_Create()
        {
            var actual = _sut.WithName("**name**").Create();

            Assert.AreEqual("**name**", actual.name);
        }

        [TestMethod]
        public void IfExpression_is_chaining()
        {
            Assert.AreSame(_sut, _sut.IfExpression("**expression**"));
        }

        [TestMethod]
        public void IfExpression_add_tSequenceFlow_to_tProcessCtor()
        {
            tFlowElement[] withParams = null;
            _sut = new tGatewayExclusiveCtor(new tProcessCtorStub(x => withParams = x), "id");

            _sut.IfExpression("expression");

            Assert.IsNotNull(withParams);
            Assert.IsNotNull(withParams[0].id);

            var tSeqFlow = (tSequenceFlow) withParams[0];
            tSeqFlow.sourceRef = "id";
            Assert.IsNotNull(tSeqFlow.conditionExpression);
            Assert.AreEqual("expression", tSeqFlow.conditionExpression.Text[0]);

        }

        [TestMethod]
        public void ThenTask_is_chaining()
        {
            Assert.AreSame(_sut, _sut.IfExpression("").ThenTask(typeof(tUserTask), "id", "name"));
        }

        [TestMethod]
        public void ThenTask_add_tTask_to_tProcessCtor_and_sets_previouss_tSequenceFlow_to_respective_tTask()
        {
            tFlowElement[] withParams = null;
            _sut = new tGatewayExclusiveCtor(new tProcessCtorStub(x => withParams = x), "id");

            _sut.IfExpression("");

            var tSeqFlow = (tSequenceFlow) withParams[0];

            _sut.ThenTask(typeof (tUserTask), "id1", "name2");

            var tUserTask = (tUserTask) withParams[0];
            tUserTask.id = "id1";
            tUserTask.name = "name2";
            tSeqFlow.targetRef = tUserTask.id;
        }

        [TestMethod]
        public void Default_is_chaining()
        {
            Assert.AreSame(_sut, _sut.Default());
        }

        [TestMethod]
        public void Default_add_tSequenceFlow_to_tProcessCtor_ThenTask_Create()
        {
            tFlowElement[] withParams = null;
            _sut = new tGatewayExclusiveCtor(new tProcessCtorStub(x => withParams = x), "id");

            _sut.Default();

            var tSeqFlow = (tSequenceFlow)withParams[0];

            _sut.ThenTask(typeof(tUserTask), "id1", "name2");

            var tUserTask = (tUserTask)withParams[0];
            tUserTask.id = "id1";
            tUserTask.name = "name2";
            tSeqFlow.targetRef = tUserTask.id;

            var result = _sut.Create();
            result.@default = tSeqFlow.id;
        }
    }
}